package br.com.prontuario.logica.impl;

import java.io.IOException;
import java.io.InputStream;
import java.util.Enumeration;
import java.util.Properties;

import org.springframework.stereotype.Service;

import br.com.prontuario.entidade.Raca;

@Service("popularRacaLogica")
public class PopularRacaLogica extends DefaultLogica<Raca> {

	private static final long serialVersionUID = 1L;
	
	public void popularRaca() throws Exception {
		Properties prop = new Properties();
		InputStream input = null;

		try {
			input = getClass().getResourceAsStream("/populador/raca.properties");
			if (input == null) {
				System.out.println("Não foi possível abrir os properties de raça");
				return;
			}

			prop.load(input);
			Enumeration<?> e = prop.propertyNames();
			while (e.hasMoreElements()) {
				String nomeRaca = (String) e.nextElement();
				nomeRaca = nomeRaca.replace("_", " ").trim();
				
				Raca raca = new Raca();
				raca.setNome(nomeRaca);
				adicionar(raca);
			}
		} catch (IOException ex) {
			ex.printStackTrace();
		} finally {
			if (input != null) {
				try {
					input.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
	}

}